const express = require("express");
const router = express.Router();

// 定义路由
router.post("/addBook", (req, res) => {
  console.log(req.body);

  res.send("响应成功");
});
// 获取图书信息
router.get("/getBooks/", (req, res) => {
  const id = req.query.id;
  res.send({
    status: 200,
    data: {
      message: "获取成功",
      books: [
        {
          id: id,
          name: "《JavaScript 高级程序设计》",
          author: "Nicholas C. Zakas",
          price: 89.0,
        },
      ],
    },
  });
});
// 更新图书信息
router.post("/updateBook", (req, res) => {
  console.log(req.body);
  res.send({
    status: 200,
    data: {
      message: "更新成功",
      book: {
        id: req.body.id,
        name: req.body.name,
        author: req.body.author,
        price: req.body.price,
      },
    },
  });
});
// 使用delete 来进行了解预检请求
router.delete("/deleteBook", (req, res) => { 
  res.send({
    status: 200,
    data: {
      message: "删除成功",
    },
  })
})
module.exports = router;
